<template>
  <el-dialog
    :visible.sync="visible"
    :close-on-click-modal="false"
    :before-close="beforeClose"
    append-to-body
    top="30px"
    width="1000px"
  >
    <el-tabs v-model="activeName">
      <el-tab-pane label="调查报告" name="file">
        <credit-file :query-id="queryId" :viewMode="true"></credit-file>
      </el-tab-pane>
      <el-tab-pane label="合同档案" name="contract" v-if="+relatedData.is_history !== 1">
        <el-tabs style="width: 90%; margin: 0 auto">
          <el-tab-pane label="委托担保合同">
            <register-contract-view
              :related-data="relatedData"
              :loading="contractLoading"
            ></register-contract-view>
          </el-tab-pane>
          <el-tab-pane label="反担保合同">
            <register-contract-view-guard
              :related-data="relatedData"
              :loading="contractLoading"
            ></register-contract-view-guard>
          </el-tab-pane>
          <el-tab-pane label="地址确认书">
            <register-contract-view-address
              :related-data="relatedData"
              :loading="contractLoading"
            ></register-contract-view-address>
          </el-tab-pane>
        </el-tabs>
      </el-tab-pane>
      <el-tab-pane label="项目附件">
        <attach-view
          :queryId="queryId"
          :related-data="relatedData"
          :visible="visible"
        ></attach-view>
      </el-tab-pane>
      <el-tab-pane label="贷后附件">
        <postloan-attach :queryId="queryId"></postloan-attach>
      </el-tab-pane>
    </el-tabs>
  </el-dialog>
</template>

<script>
import CreditFile from '@/credit/components/creditFile/InvestigateReport'
import AttachView from '@/credit/views/city/mission/postloan/AttachView'
import RegisterContractView from '@/credit/views/county/mission/RegisterContractView'
import RegisterContractViewGuard from '@/credit/views/county/mission/RegisterContractViewGuard'
import RegisterContractViewAddress from '@/credit/views/county/mission/RegisterContractViewAddress'
import PostloanAttach from '@/credit/views/city/mission/postloan/PostloanAttach'
export default {
  components: {
    CreditFile,
    AttachView,
    PostloanAttach,
    RegisterContractView,
    RegisterContractViewGuard,
    RegisterContractViewAddress,
  },
  props: {
    visible: Boolean,
    relatedData: Object,
  },
  computed: {
    queryId() {
      return this.relatedData.customer_related_id
    },
  },
  watch: {
    relatedData: {
      handler: function () {
        this.activeName = 'file'
        this.getContract(this.queryId)
      },
      deep: true,
    },
  },
  data() {
    return {
      activeName: 'file',
      contractLoading: false,
    }
  },
  methods: {
    beforeClose() {
      this.$emit('close', false)
      this.$emit('update:visible', false)
    },
    async getContract(relatedId) {
      if (!relatedId) return
      this.contractLoading = true
      await this.$utils.promise(
        Promise.all([
          this.$store.dispatch('getEntrustContract', relatedId),
          this.$store.dispatch('getGuardsData', relatedId),
        ])
      )
      this.contractLoading = false
    },
  },
}
</script>

<style></style>
